﻿using Obtics.Collections;

#if TVDP_UNITTESTING
using TvdP.UnitTesting;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif


using System.Collections.Generic;
using System;
using Obtics.Values;
using System.Collections;
using System.Linq;

namespace ObticsUnitTest.Obtics.Collections
{
    
    
    /// <summary>
    ///This is a test class for ObservableEnumerableTest and is intended
    ///to contain all ObservableEnumerableTest Unit Tests
    ///</summary>
    public partial class ObservableEnumerableTest
    {
        [TestMethod]
        public void ThenByDescendingTest1()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1])
                ),
                "ThenByDescendingTest1(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, char>(s => s[1]);

            Assert.AreEqual(
                ObservableEnumerable.ThenByDescending(seq, sel),
                ObservableEnumerable.ThenByDescending(seq, sel),
                "ThenByDescendingTest1(b)"
            );
        }

        [TestMethod]
        public void ThenByDescendingTest2()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]))
                ),
                "ThenByDescendingTest2(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));

            Assert.AreEqual(
                ObservableEnumerable.ThenByDescending(seq, sel),
                ObservableEnumerable.ThenByDescending(seq, sel),
                "ThenByDescendingTest2(b)"
            );
        }

        [TestMethod]
        public void ThenByDescendingTest3()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1], Comparer<char>.Default)
                ),
                "ThenByDescendingTest3(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, char>(s => s[1]);
            var comp = Comparer<char>.Default;

            Assert.AreEqual(
                ObservableEnumerable.ThenByDescending(seq, sel, comp),
                ObservableEnumerable.ThenByDescending(seq, sel, comp),
                "ThenByDescendingTest3(b)"
            );
        }

        [TestMethod]
        public void ThenByDescendingTest4()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]), Comparer<char>.Default)
                ),
                "ThenByDescendingTest4(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));
            var comp = Comparer<char>.Default;

            Assert.AreEqual(
                ObservableEnumerable.ThenByDescending(seq, sel, comp),
                ObservableEnumerable.ThenByDescending(seq, sel, comp),
                "ThenByDescendingTest4(b)"
            );
        }

        [TestMethod]
        public void ThenByDescendingTest5()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1])
                ),
                "ThenByDescendingTest5(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, char>(s => s[1]);

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenByDescending(seq, sel),
            //    ObservableEnumerable.ThenByDescending(seq, sel),
            //    "ThenByDescendingTest5(b)"
            //);
        }

        [TestMethod]
        public void ThenByDescendingTest6()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]))
                ),
                "ThenByDescendingTest6(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenByDescending(seq, sel),
            //    ObservableEnumerable.ThenByDescending(seq, sel),
            //    "ThenByDescendingTest6(b)"
            //);
        }

        [TestMethod]
        public void ThenByDescendingTest7()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1], Comparer<char>.Default)
                ),
                "ThenByDescendingTest7(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, char>(s => s[1]);
            //var comp = Comparer<char>.Default;

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenByDescending(seq, sel, comp),
            //    ObservableEnumerable.ThenByDescending(seq, sel, comp),
            //    "ThenByDescendingTest7(b)"
            //);
        }

        [TestMethod]
        public void ThenByDescendingTest8()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AB", "AA", "BB", "BA" },
                    ObservableEnumerable.ThenByDescending(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]), Comparer<char>.Default)
                ),
                "ThenByDescendingTest8(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));
            //var comp = Comparer<char>.Default;

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenByDescending(seq, sel, comp),
            //    ObservableEnumerable.ThenByDescending(seq, sel, comp),
            //    "ThenByDescendingTest8(b)"
            //);
        }
    
    }
}
